package com.adwszzy;

import com.alibaba.fastjson2.JSONObject;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * json配置读取为JsonObject对象方便使用
 */
public class ConfigurationMaps {
    public static JSONObject c1Info;
    public static JSONObject c3Info;
    public static JSONObject c4Info;
    public static JSONObject priorityInfo;
    public static JSONObject suitInfo;
    static{
        load();
    }
    public static void load(){
        c1Info = readFile(ConfigConstants.c1Conf);
        c3Info = readFile(ConfigConstants.c3Conf);
        c4Info = readFile(ConfigConstants.c4Conf);
        priorityInfo = readFile(ConfigConstants.priorityConf);
        suitInfo = readFile(ConfigConstants.suitConf);
    }
    public static JSONObject readFile(String filePath){
//        String filePath = "path/to/your/jsonfile.json"; // 指定你的JSON文件路径

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            StringBuilder jsonString = new StringBuilder();
            String line;

            while ((line = reader.readLine()) != null) {
                jsonString.append(line);
            }

            JSONObject jsonObject = JSONObject.parseObject(jsonString.toString());
            return jsonObject;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
